import request from "@/utils/request"
import { remoteRequest } from '@/utils/remote.js'

// 新增
export function save(baseUrl, data) {
  return request({
    url: `${baseUrl}/save`,
    method: "post",
    data
  })
}
// 查询
export function getAll(baseUrl, params) {
  return request({
    url: `${baseUrl}/getAll`,
    method: "get",
    params
  })
}
// 详情
export function getById(baseUrl, id) {
  return request({
    url: `${baseUrl}/getById/${id}`,
    method: "get"
  })
}
// 删除
export function deleteList(baseUrl, id) {
  return request({
    url: `${baseUrl}/delete/${id}`,
    method: "post"
  })
}
// 修改
export function update(baseUrl, data) {
  return request({
    url: `${baseUrl}/update`,
    method: "post",
    data
  })
}
// 显示列
export function getField(baseUrl) {
  return request({
    url: `${baseUrl}/getField`,
    method: "get"
  })
}

// 保存显示列
export function fieldOption(baseUrl, data) {
  return request({
    url: `${baseUrl}/fieldOption`,
    method: "post",
    data
  })
}
// 内部数据
export function download(id) {
  return request({
    url: `/modules/internalData/downLoadFile?id=${id}`,
    method: "get",
    responseType: 'blob'
  })
}

export function getId(baseUrl, data) {
  return remoteRequest('getId', { baseUrl, data }, () => {
    return request({
      url: `${baseUrl}/getId`,
      method: "post",
      data
    })
  })
}

export function checkId(baseUrl, data) {
  return remoteRequest('checkId', data, () => {
    let { id, smId, key } = data
    return request({
      url: `${baseUrl}/checkId?id=${id}&smId=${smId}&key=${key}`,
      method: "post"
    })
  })
}

// 提交质检
export function submit(baseUrl, data) {
  return request({
    url: `${baseUrl}/submit/${data}`,
    method: "post"
  })
}